package com.talend.support.dashboard.beans;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import org.primefaces.event.ItemSelectEvent;
import org.primefaces.model.chart.ChartSeries;
import org.primefaces.model.chart.PieChartModel;

@SuppressWarnings("serial")
@ManagedBean
@RequestScoped
public class PieChart implements Serializable {

	private PieChartModel pieModel;

	public PieChart() {
	}

	public void itemSelect(ItemSelectEvent event) {
		FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,
				"Item selected", "Item Index: " + event.getItemIndex()
						+ "Serie Index:" + event.getSeriesIndex());
		FacesContext.getCurrentInstance().addMessage(null, msg);
	}

	public PieChartModel getPieModel() {
		return pieModel;
	}

	@PostConstruct
	public void init() {
		pieModel = new PieChartModel();

		ChartSeries rate = new ChartSeries();
		rate.setLabel("Rate");

		pieModel.set("Excellent", 12);
		pieModel.set("Good", 47);
		pieModel.set("Average", 38);
		pieModel.set("Poor", 3);
	}
}